<?php
class Database{	
	var $host;
	var $password;
	var $base;
	var $db;
	var $isConnected;
	var $singleCall;
	
	function Database($host,$login,$pass,$base,$singleCall=false)
	{
		$this->host = $host;
		$this->login = $login;
		$this->password = $pass;
		$this->base= $base;
		$this->singleCall= $singleCall;
		$this->isConnected=false;
	}

	function connect()
	{
		$this->db = @mysql_connect($this->host,$this->login,$this->password);
		if(!$this->db) return 2; // Code erreur de connexion
		if(!@mysql_select_db($this->base)) return 3; // Code erreur de selection de base
		$this->isConnected = true;
		return 1; // Code de retour normal.
	}

	function query($query)
	{		
		if(!$this->isConnected){
			$this->connect();
		}
		$resultat = mysql_query($query) or die("Erreur d'execution de la requete - ".mysql_error()." Requete : ".$query);
		if($this->singleCall){
			$this->close();
		}
		return $resultat;
	}

	function close()
	{
		mysql_close();
		$this->isConnected=false;
	}
	
	function selectAll($table)
	{
		return $this->query("SELECT * FROM ".$table.";");
	}
}
?>